package com.example.app.components


import android.widget.GridLayout
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.GridCells
import androidx.compose.foundation.lazy.LazyVerticalGrid
import androidx.compose.foundation.lazy.items
import androidx.compose.material.Card
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun LazyVerticalGrids() {
    var data: List<Int> = listOf(1,2,3,4,5,6,7,8,9,0)
    // cell 单元格展示形式(全部填充/固定大小)
    // cells = GridCells.Fixed(3)每行3列
    // GridCells.Adaptive(100.dp)自适应模式,参数为最小宽度
    LazyVerticalGrid(cells = GridCells.Adaptive(100.dp)) {
        items(data) {
            Card() {
                Text(
                    text = "Grid ${it}",
                    modifier = Modifier
                        .background(Color.Blue)
                        .padding(20.dp)
                )
            }
        }
    }
}

@Preview(
    showSystemUi = true
)
@Composable
fun LazyVerticalGridPreview() {
    LazyVerticalGrids()
}

